﻿using System;
using System.Reflection;

namespace Borg
{
    [Serializable]
    public abstract class AssemblyElement : Qualifiable
    {
        internal Runtime runtime;

        private AssemblyState _assemblyState;
        private AssemblyName _assemblyName;

        private readonly Uri _originUri;
        private readonly Uri _assemblyUri;
        private readonly Uri _environmentUri;

        private readonly string _analyzerId;

        public AssemblyState AssemblyState
        {
            get { return _assemblyState; }
            internal set { _assemblyState = value; }
        }

        public AssemblyName AssemblyName
        {
            get { return _assemblyName; }
            internal set { _assemblyName = value; }
        }

        public Uri OriginUri
        {
            get { return _originUri; }
        }

        public Uri AssemblyUri
        {
            get { return _assemblyUri; }
        }

        public Uri EnvironmentUri
        {
            get { return _environmentUri; }
        }

        public string AnalyzerId
        {
            get { return _analyzerId; }
        }

        internal AssemblyElement(string analyzerId, Runtime runtime, int id,
            string name, Uri orignUri, Assembly assembly, Uri environmentUri)
            : this(analyzerId, runtime, id, name, orignUri, assembly.IsDynamic
                ? null : new Uri(assembly.EscapedCodeBase), environmentUri)
        { }

        internal AssemblyElement(string analyzerId, Runtime runtime, int id,
            string name, Uri originUri, Uri assemblyUri, Uri environmentUri)
            : base(id, name)
        {
            this.runtime = runtime;
            _analyzerId = analyzerId ?? string.Empty;
            _originUri = originUri;
            _assemblyUri = assemblyUri;
            _environmentUri = environmentUri;
        }

        internal override AssemblyElement GetAssemblyElement()
        {
            return this;
        }
    }
}

